語法:C# 工具:Visual Studio 2022
private void button1_Click(object sender, EventArgs e)
{
Cursor.Position = PointToScreen(button2.Location); //滑鼠指標放在兩個按鈕之間互相跳動
textBox1.Focus();
System.Diagnostics.Process.Start(@"C:\Windows\system32\osk.exe");
}
按下button1
private void button2_Click(object sender, EventArgs e)
{
button2.Cursor = System.Windows.Forms.Cursors.Hand; //將按鈕的滑鼠指標游標變更為手部
Cursor.Position = PointToScreen(button1.Location);
}
button2.Cursor = System.Windows.Forms.Cursors.Hand;
滑鼠游標移動到button2上方,就會產生變化成指定圖案的效果,Hand代表手掌圖案
完整程式代碼
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 滑鼠指標放在兩個按鈕之間
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Control_MouseDown(object sender, MouseEventArgs e)
{
lblOutput.Text = "X=" + e.X + "Y=" + e.Y;
}
private void Control_MouseUp(object sender, MouseEventArgs e)
{
string output = "";
switch (e.Button)
{
case MouseButtons.Left:
output = "左鍵";
break;
case MouseButtons.Middle:
output = "中鍵";
break;
case MouseButtons.Right:
output = "右鍵";
break;
}
this.Text = output;
}
private void button1_Click(object sender, EventArgs e)
{
Cursor.Position = PointToScreen(button2.Location);
//滑鼠指標放在兩個按鈕之間互相跳動
textBox1.Focus();
System.Diagnostics.Process.Start(@"C:\Windows\system32\osk.exe");
}
private void button2_Click(object sender, EventArgs e)
{
button2.Cursor = System.Windows.Forms.Cursors.Hand;
//將按鈕的滑鼠指標游標變更為手部
Cursor.Position = PointToScreen(button1.Location);
}
}
}
在Windows10 x64,於Visual Studio中呼叫螢幕小鍵盤(OSK),方案平台一定要切換為64位元,如圖紅框處所示。
程式執行畫面